<?php
class models_tintuc extends connect{
	
	function _listtintuc()
	{
		$sql = 'SELECT * FROM tintuc';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
   function _listtintucmoi()
	{
		$sql = 'SELECT MaTin, TieuDe, NoiDung, AnHien 
				FROM tintuc 
				WHERE AnHien=1
				limit 0,5';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
	
	function _addtintuc($TieuDe,$NoiDung,$AnHien)
	{
		$sql = "INSERT INTO tintuc VALUES ('', '$TieuDe', '$NoiDung', '$AnHien')";
		$this->query_db($sql);
	}
	function _delTinTuc($id){
		$sql = "
				DELETE 
				FROM tintuc
				WHERE MaTin = '$id'";
		$this->query_db($sql);
	}
	function _getTinTuc($id){
		$sql = "
				SELECT MaTin,TieuDe, NoiDung, AnHien
				FROM tintuc
				WHERE MaTin = '$id'";
		$this->query_db($sql);
		return $this->fetchOne();
	}
	function _updateTinTuc($TieuDe,$NoiDung,$AnHien,$id){
		$sql = "UPDATE tintuc
				SET 
				    TieuDe = '$TieuDe', 
					NoiDung = '$NoiDung',
					AnHien = '$AnHien'
					WHERE MaTin = '$id'";
		$this->query_db($sql);
	}
}
?>